package cn.gson.crm.controller.pay;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.gson.crm.controller.BaseServlet;
import cn.gson.crm.model.dao.StudentDetailDao;
import cn.gson.crm.model.dao.StudentPayDao;
import cn.gson.crm.model.entity.StudentDetail;
import cn.gson.crm.model.po.StudentPayPo;

@WebServlet("/student/haventpay")
public class HaventPayStudentServlet extends BaseServlet{
	/**
	 * 未缴清学费学员
	 */
	private static final long serialVersionUID = 1L;
	private StudentPayDao stuPayDao = new StudentPayDao();

	@Override
	protected void get(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String p = request.getParameter("page");
		String name = request.getParameter("name");
		if(p == null || p.isEmpty()){
			p = "1";
		}
		Integer page = Integer.parseInt(p);
		//获取未交清学费的学员
		List<StudentPayPo> stuList = stuPayDao.getStudentList(page,"正常", "已分配", name,1);
		List<StudentPayPo> payList = null;
		if(stuList!=null){
			payList = new ArrayList<>();
			for (StudentPayPo payPo : stuList) {
				StudentPayPo po = stuPayDao.getPayRecord(payPo.getId().toString());
				if(po!=null){
					payPo.setNoPay(po.getNoPay());
					payPo.setDuePay(po.getDuePay());
					payPo.setPayDate(po.getPayDate());
				}
				payList.add(payPo);
			}
		}
		int totalPage = stuPayDao.getTotalPage("正常", "已分配", name, 1);
		request.setAttribute("page", page);
		request.setAttribute("stuList", payList);
		request.setAttribute("totalPage", totalPage);
		request.setAttribute("queryString", noPageQueryString(request));
		getServletPathAndForward(request, "pay/student_pay.jsp");
	}
}
